// @ts-ignore
/* eslint-disable */

/**
 * 该文件为 @umijs/openapi 插件自动生成，请勿随意修改。如需修改请通过配置 openapi.config.ts 进行定制化。
 * */

import { request, type RequestOptions } from '@/utils/request';

/** 根据文件名称+后缀删除文件，例如《二次续签附件.pdf》 GET /minio/delete */
export async function minioDeleteFile(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.MinioDeleteFileParams,
  options?: RequestOptions
) {
  return request<any>('/minio/delete', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 获取某个存储桶的所有内容 GET /minio/getbucketlist */
export async function minioGetBucketList(options?: RequestOptions) {
  return request<any>('/minio/getbucketlist', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 上传 POST /minio/upload */
export async function minioUpload(
  body: API.MinioUploadDto,
  file?: File,
  options?: RequestOptions
) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach(ele => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach(f => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<any>('/minio/upload', {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}
